<?php 

    /**
     * This file is part of the Intelligencer package.
     * For the full copyright and license, please view the LICENSE
     * file that was distributed with this source code.
     * 
     * @author      drapeko <roman.drapeko@gmail.com>
     * @copyright   Roman Drapeko <roman.drapeko@gmail.com>, 2009 - present
     */

    require_once dirname(__FILE__).'/../Intelligencer/itLoader.php';
    
    /**
     * This class loads the Intelligencer framework on demand
     * @author drapeko
     */
    class itTestLoader {
        
        protected static $classes = array(
            'itIntelligencerTest'                 => 'Test/Intelligencer',
            'itRulesIntelligencerTest'            => 'Test/Intelligencer',
            'itTemplateIntelligencerTest'         => 'Test/Intelligencer',
            'itCacheTest'                         => 'Test/LibUtil/Cache',
            'itLocalCacheTest'                    => 'Test/LibUtil/Cache',
            'itPersistentCacheTest'               => 'Test/LibUtil/Cache',
            'itPersistentCacheableITest'          => 'Test/LibUtil/Cache',
            'itExceptionTest'                     => 'Test/LibUtil/Exception',
            'itParameterExceptionTest'            => 'Test/LibUtil/Exception',
            'itScannerTest'                       => 'Test/LibUtil/Scanner',
            'itScannerITest'                      => 'Test/LibUtil/Scanner',
            'itScannerResultITest'                => 'Test/LibUtil/Scanner',
            'itScannerResultTest'                 => 'Test/LibUtil/Scanner',
            'itUtilTest'                          => 'Test/LibUtil',
            'itManagerTest'                       => 'Test/Manager',
            'itRulesTest'                         => 'Test/Rules',
            'itClassRulesTest'                    => 'Test/Rules',
            'itClassRulesConvertibleITest'        => 'Test/Rules',
            'itComplexRulesTest'                  => 'Test/Rules',
            'itSimpleRulesTest'                   => 'Test/Rules',
            'itSimpleRulesConvertibleITest'       => 'Test/Rules',
            'itSimpleTemplateTest'                => 'Test/Template',
            'itTemplateTest'                      => 'Test/Template',
            'itZendStyleTemplateTest'             => 'Test/Template',
            'itTestCase'                          => '.',
        );
        
        protected static $lowerClasses = null;
        
        protected static $loader = null;

        protected static function doLowerClasses() {
            $ds = DIRECTORY_SEPARATOR;
            foreach(self::$classes as $class => $dir) {
                self::$lowerClasses[strtolower($class)] = $dir.$ds.$class.'.php';
            }
        }
        
        public static function register() {
            self::doLowerClasses();
            set_include_path(dirname(__FILE__) . PATH_SEPARATOR . get_include_path());
            define('TEST_DATA', dirname(__FILE__).'/Data');
            define('TEST_SRC', dirname(__FILE__).'/Test');
            spl_autoload_register(array(__CLASS__, 'autoload'));
        }
        
        public static function unregister() {
            spl_autoload_unregister(array(__CLASS__, 'autoload'));
        }
        
        public static function autoload($className) {
            if (substr(__CLASS__, 0, 2) == 'it') {
                $lowerClass = strtolower($className);
                if (array_key_exists($lowerClass, self::$lowerClasses)) {
                    $ds = DIRECTORY_SEPARATOR;
                    $file = dirname(__FILE__).$ds.self::$lowerClasses[$lowerClass];
                    if (is_file($file)) {
                        require_once $file;
                    }
                }
            }
        }
    }

    itTestLoader::register();

?>